package com.tr.rentcar.controller.home;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.tr.rentcar.model.bean.Employee;
import com.tr.rentcar.model.dao.EmployeeDao;

/**
 * Servlet 
 */
@WebServlet("/findname")
public class DriverNameController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	EmployeeDao ed=new EmployeeDao();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		String val=request.getParameter("val");
		//根据模糊查询显示司机姓名
		try {
			if (val=="") {
				List<Employee> elist=ed.findAll();
				out.print(JSONArray.toJSONString(elist));
			}else{
				List<Employee> elist=ed.findNameByVal(val);
				out.print(JSONArray.toJSONString(elist));
			}
			out.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

}
